package com.fyy.minio.jsl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fyy.minio.utils.MD5Util;
import okhttp3.*;

import java.io.IOException;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

public class GetPicApiTest {

    public final static String CLIENT_ID = "webcuClient";
    public final static String CLIENT_SECRET = "B3)E0$W6_N3^B5*A7>D2?Y6;R0(B9@D4";
    public final static String USERNAME = "test221011";
    public final static String PASSWORD = "Rc22@*(8HTq68hs2";
    public final static String URI = "http://123.13.218.244:1084/pic/list";
    public final static String S1 = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsib2F1dGgyLXJlc291cmNlIl0sInVzZXJfbmFtZSI6InRlc3QyMjEwMTEiLCJzY29wZSI6WyJhbGwiXSwiY29tcGFueSI6InNhbnRhY2hpIiwiZXhwIjoxNjY1NTY1OTU0LCJhdXRob3JpdGllcyI6WyJST0xFX0FETUlOIl0sImp0aSI6ImFjM2Y3MzdjLTg2M2UtNDI3NC1iMDJkLWUwNWU1OWU2NzAwOSIsImNsaWVudF9pZCI6IndlYmN1Q2xpZW50In0.9mI0Lm1OCipTsc8XP6TA_fYFDnSMEezEU6TQQLlaAco";

    public static void main(String[] args) throws IOException {

        OkHttpClient client = new OkHttpClient().newBuilder().build();
        MediaType mediaType = MediaType.parse("application/json");
        Map<String,String> params = new HashMap<>();
        params.put("page","1");
        params.put("rows","30");
        params.put("sdate","20221012090000");
        params.put("edate","20221012595959");
        String s = JSONObject.toJSONString(params);
        RequestBody body = RequestBody.create(mediaType,s.toString());
        Request request = new Request.Builder()
                .url(URI)
                .method("POST",body)
                .addHeader("Authorization","bearer " + S1)
                .addHeader("Content-Type","application/json")
                .build();
        Response response = client.newCall(request).execute();
        System.out.println("请求结果：" + response.code());
        if(response.isSuccessful()){
            String string = response.body().string();
            System.out.println(string);
            JSONObject jsonObject = JSONObject.parseObject(string);
            JSONArray array = JSONArray.parseArray(jsonObject.get("data").toString());
            System.out.println(array.size());
        }

    }

}
